/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View;

import Control.OntologyController;
import Control.OntologyPrinterController;
import Control.SemanticQualificationController;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeModelEvent;
import javax.swing.event.TreeModelListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
import org.semanticweb.owlapi.model.OWLOntologyCreationException;

/**
 *
 * @author Hicham
 */

public class PrincipalWindowGUI extends javax.swing.JFrame {

    private JFileChooser openFile; // the owl file or the html file
    private TreeModel ontologyTreeModel = null;
    private TreeModel ontologyTreeModelWithoutAttributes = null;
    private TreeModel formTreeModel = null;
    private String ontologyUrl;
    private String htmlFormUrl;
    private boolean displayAttributes = true;
    private String textSelected;
    private DefaultMutableTreeNode tempNode;
    private SemanticQualificationController sqc;

    /**
     * Creates new form ModelGUI
     */
    public PrincipalWindowGUI() {
        super("NEREID ePortfolio Project - INSA Lyon France - UdeC Chile");
        
        initComponents();
        this.sqc = new SemanticQualificationController();
        jPanelContainer.setVisible(false);
        ontologyTree.setModel(ontologyTreeModel);
        formTree.setModel(formTreeModel);
        
        buttonGroupDisplayAttributes.add(jRadioButtonAttOn);
        buttonGroupDisplayAttributes.add(jRadioButtonAttOff);
        jRadioButtonAttOn.setSelected(true);
        
        /* Setting the ontology tree
        Icon openIcon = new ImageIcon("C:\\Users\\Toinamph\\plus.png");
        Icon closedIcon = new ImageIcon("C:\\Users\\Toinamph\\minus.png");
        ((javax.swing.plaf.basic.BasicTreeUI) ontologyTree.getUI()).setExpandedIcon(openIcon);
        ((javax.swing.plaf.basic.BasicTreeUI) ontologyTree.getUI()).setCollapsedIcon(closedIcon);
        ImageIcon classIcon = new ImageIcon("C:\\Users\\Toinamph\\plus.png");
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
        renderer.setClosedIcon(classIcon);
        renderer.setOpenIcon(classIcon);
        ontologyTree.setCellRenderer(renderer);
        */

        ImageIcon conceptIcon = new ImageIcon("..\\trunk\\img\\plus.png");
        ImageIcon attributeIcon = new ImageIcon("..\\trunk\\img\\minus.png");

        ontologyTree.setCellRenderer( new MyTreeRenderer(conceptIcon, attributeIcon) );
        // to uncomment when the methd setHtmlFormtree is done :
        // formTree.setModel(formTreeModel);
    }

    /**
     * set the ontology tree using the ontology object from the model.
     */
    public void setOntologyTree() {
        try {
            OntologyController.parseOWL(ontologyUrl);
            JTree jtree = new JTree(OntologyPrinterController.createTreeNodes(OntologyController.getOntology(), true));
            ontologyTreeModel = jtree.getModel();
            //jLabelOntology.setText("ONTOLOGY : " + OntologyController.getOntology().getName());
            jLabelOntologyName.setText(OntologyController.getOntology().getName());
            
            jtree = new JTree(OntologyPrinterController.createTreeNodes(OntologyController.getOntology(), false));
            ontologyTreeModelWithoutAttributes = jtree.getModel();
            
            if(displayAttributes) {
                ontologyTree.setModel(ontologyTreeModel);
            }
            else {
                ontologyTree.setModel(ontologyTreeModelWithoutAttributes);
            }
            PrincipalWindowGUI.MyTreeListener mtl = new PrincipalWindowGUI.MyTreeListener();
            ontologyTree.addTreeSelectionListener(mtl);  
            ontologyTree.addTreeExpansionListener(mtl);
            ontologyTreeModel.addTreeModelListener(mtl);
        } catch (OWLOntologyCreationException ex) {
            Logger.getLogger(PrincipalWindowGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * set the ontology tree using a concept name..
     *
     * @param conceptName
     */
    private void setOntologyTree(String conceptName) {
        if (conceptName != null && !conceptName.isEmpty() && !conceptName.equals("Search...")) {
            JTree jtree = new JTree(OntologyPrinterController.createTreeNodes(conceptName, displayAttributes));
            ontologyTree.setModel(jtree.getModel());
        } else {
            if(displayAttributes) {
                ontologyTree.setModel(ontologyTreeModel);
            } else {
                ontologyTree.setModel(ontologyTreeModelWithoutAttributes); // we display the whole ontology
            }
        }

    }
    
    /**
     * Set the ontology form using the form object from the model.
     */
    private void setHtmlFormTree() {
        // TODO for Mariana and Daniel : parse the html file and display it
        /*try {
            HTMLFormController.parseHTML(htmlFormUrl);
            jLabelFormName.setText("FORM : " + HTMLFormController.getForm().getName());
            SemanticQualificationController.setForm(HTMLFormController.getForm());
        } catch (Exception ex) {
            Logger.getLogger(PrincipalWindowGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
        */
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    public void setOntologyURL(String url){
        ontologyUrl = url;
    }
    
    public String getTextSelected(){
        return textSelected;
    }
    
    public JScrollPane getJScrollPane4(){
        return jScrollPane4;
    }
    
    public String getOntologyName(){
        return jLabelOntologyName.getText();
    }
    
    
private class MyTreeListener implements TreeExpansionListener, TreeModelListener, TreeSelectionListener {

    private Object[] tempNodes;
    private StringBuffer tempMsg = new StringBuffer();
    private TreePath tp;    
    
    public void valueChanged(TreeSelectionEvent tse) {
        tp = tse.getNewLeadSelectionPath();
        if (tp != null) {
            tempNodes = tp.getPath();
            for (int i = 0; i < tempNodes.length; i++) {
                tempMsg.append(tempNodes[i]);
                if (i != tempNodes.length - 1) {
                    tempMsg.append(">>");
                }
            }
            System.out.println("You have chosen the node ： " + tempMsg.toString() + "！！！");
            tempMsg.delete(0, tempMsg.length());
            tempNode = (DefaultMutableTreeNode) tp.getLastPathComponent();
            textSelected = tempNode.toString();
            System.out.println("Text selected is " + textSelected);
        }
    }

    public void treeCollapsed(TreeExpansionEvent tee) {
        tp = tee.getPath();
        System.out.println("You have collapsed the node : " + tp.getLastPathComponent() + "！！！");
    }
    public void treeExpanded(TreeExpansionEvent tee) {
       tp = tee.getPath();
       System.out.println("You have expanded the node : " + tp.getLastPathComponent() + "！！！");
    }
    public void treeNodesChanged(TreeModelEvent tme) {
       System.out.println("You have changed the title of the node！！！");
    }
    public void treeStructureChanged(TreeModelEvent tme) {}
    public void treeNodesRemoved(TreeModelEvent tme) {}
    public void treeNodesInserted(TreeModelEvent tme) {}
}
    
    public javax.swing.JButton getSaveSemQuaBtn(){
        return saveSemQuaBtn;
    }
    
    public SemanticQualificationController getSQC(){
        return sqc;
    }


    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroupDisplayAttributes = new javax.swing.ButtonGroup();
        jPanelContainer = new javax.swing.JPanel();
        jPanelFormPart = new javax.swing.JPanel();
        openHtmlBtn = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        formTree = new javax.swing.JTree();
        jPanelOntologyPart = new javax.swing.JPanel();
        jPanelOntologyHeader = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jRadioButtonAttOn = new javax.swing.JRadioButton();
        openOwlBtn = new javax.swing.JButton();
        jLabelOntologyName = new javax.swing.JLabel();
        jRadioButtonAttOff = new javax.swing.JRadioButton();
        jPanelOntologyDisplay = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ontologyTree = new javax.swing.JTree();
        jTextFieldSearch = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jPanelSemQualPart = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jButtonNewFormalConcept = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        saveSemQuaBtn = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        jMenuAbout = new javax.swing.JMenuItem();
        jMenuQuit = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenu1 = new javax.swing.JMenu();
        jMenuNewSemanticQual = new javax.swing.JMenuItem();
        jMenuOpenOntology = new javax.swing.JMenuItem();
        jMenuNewFormalConcept = new javax.swing.JMenuItem();
        jMenuSaveSemQual = new javax.swing.JMenuItem();
        jMenu5 = new javax.swing.JMenu();
        jMenuOpenForm = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuOnlineHelp = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanelContainer.setOpaque(false);

        jPanelFormPart.setBackground(new java.awt.Color(102, 255, 51));
        jPanelFormPart.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Formulary", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 204))); // NOI18N
        jPanelFormPart.setForeground(new java.awt.Color(0, 0, 204));
        jPanelFormPart.setMinimumSize(new java.awt.Dimension(0, 0));

        openHtmlBtn.setText("Open...");
        openHtmlBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openHtmlBtnActionPerformed(evt);
            }
        });

        formTree.setBackground(new java.awt.Color(204, 255, 204));
        jScrollPane3.setViewportView(formTree);

        javax.swing.GroupLayout jPanelFormPartLayout = new javax.swing.GroupLayout(jPanelFormPart);
        jPanelFormPart.setLayout(jPanelFormPartLayout);
        jPanelFormPartLayout.setHorizontalGroup(
            jPanelFormPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFormPartLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelFormPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 214, Short.MAX_VALUE)
                    .addGroup(jPanelFormPartLayout.createSequentialGroup()
                        .addComponent(openHtmlBtn)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanelFormPartLayout.setVerticalGroup(
            jPanelFormPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelFormPartLayout.createSequentialGroup()
                .addComponent(openHtmlBtn)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 327, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanelOntologyPart.setBackground(new java.awt.Color(51, 255, 204));
        jPanelOntologyPart.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Ontology", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanelOntologyPart.setMinimumSize(new java.awt.Dimension(0, 0));
        jPanelOntologyPart.setPreferredSize(new java.awt.Dimension(311, 1000));

        jPanelOntologyHeader.setBackground(new java.awt.Color(0, 255, 204));
        jPanelOntologyHeader.setMaximumSize(new java.awt.Dimension(32767, 51));

        jLabel1.setText("Display Attributes");

        jRadioButtonAttOn.setBackground(new java.awt.Color(51, 255, 204));
        jRadioButtonAttOn.setText("On");
        jRadioButtonAttOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAttOnActionPerformed(evt);
            }
        });

        openOwlBtn.setText("Open...");
        openOwlBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openOwlBtnActionPerformed(evt);
            }
        });

        jRadioButtonAttOff.setBackground(new java.awt.Color(0, 255, 204));
        jRadioButtonAttOff.setText("Off");
        jRadioButtonAttOff.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonAttOffActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelOntologyHeaderLayout = new javax.swing.GroupLayout(jPanelOntologyHeader);
        jPanelOntologyHeader.setLayout(jPanelOntologyHeaderLayout);
        jPanelOntologyHeaderLayout.setHorizontalGroup(
            jPanelOntologyHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOntologyHeaderLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOntologyHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelOntologyHeaderLayout.createSequentialGroup()
                        .addComponent(jLabelOntologyName, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanelOntologyHeaderLayout.createSequentialGroup()
                        .addComponent(openOwlBtn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButtonAttOn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jRadioButtonAttOff)
                        .addGap(12, 12, 12))))
        );
        jPanelOntologyHeaderLayout.setVerticalGroup(
            jPanelOntologyHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOntologyHeaderLayout.createSequentialGroup()
                .addGroup(jPanelOntologyHeaderLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(openOwlBtn)
                    .addComponent(jRadioButtonAttOn)
                    .addComponent(jRadioButtonAttOff))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelOntologyName, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        jPanelOntologyDisplay.setBackground(new java.awt.Color(0, 255, 204));
        jPanelOntologyDisplay.setPreferredSize(new java.awt.Dimension(120, 1000));

        jScrollPane1.setPreferredSize(new java.awt.Dimension(100, 1000));

        ontologyTree.setBackground(new java.awt.Color(153, 255, 204));
        ontologyTree.setMaximumSize(new java.awt.Dimension(1000, 1000));
        ontologyTree.setPreferredSize(new java.awt.Dimension(72, 1000));
        jScrollPane1.setViewportView(ontologyTree);

        jTextFieldSearch.setBackground(new java.awt.Color(204, 255, 204));
        jTextFieldSearch.setMaximumSize(new java.awt.Dimension(2147483647, 25));
        jTextFieldSearch.setPreferredSize(new java.awt.Dimension(51, 25));
        jTextFieldSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextFieldSearchActionPerformed(evt);
            }
        });

        jLabel2.setText("Search:");

        javax.swing.GroupLayout jPanelOntologyDisplayLayout = new javax.swing.GroupLayout(jPanelOntologyDisplay);
        jPanelOntologyDisplay.setLayout(jPanelOntologyDisplayLayout);
        jPanelOntologyDisplayLayout.setHorizontalGroup(
            jPanelOntologyDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOntologyDisplayLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelOntologyDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelOntologyDisplayLayout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
        );
        jPanelOntologyDisplayLayout.setVerticalGroup(
            jPanelOntologyDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOntologyDisplayLayout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 297, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelOntologyDisplayLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addGap(7, 7, 7))
        );

        javax.swing.GroupLayout jPanelOntologyPartLayout = new javax.swing.GroupLayout(jPanelOntologyPart);
        jPanelOntologyPart.setLayout(jPanelOntologyPartLayout);
        jPanelOntologyPartLayout.setHorizontalGroup(
            jPanelOntologyPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelOntologyPartLayout.createSequentialGroup()
                .addGroup(jPanelOntologyPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanelOntologyDisplay, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 289, Short.MAX_VALUE)
                    .addComponent(jPanelOntologyHeader, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanelOntologyPartLayout.setVerticalGroup(
            jPanelOntologyPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelOntologyPartLayout.createSequentialGroup()
                .addComponent(jPanelOntologyHeader, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelOntologyDisplay, javax.swing.GroupLayout.DEFAULT_SIZE, 335, Short.MAX_VALUE)
                .addContainerGap())
        );

        jPanelSemQualPart.setBackground(new java.awt.Color(255, 255, 255));
        jPanelSemQualPart.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED), "Semantic Qualification", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 1, 11), new java.awt.Color(0, 0, 255))); // NOI18N
        jPanelSemQualPart.setForeground(new java.awt.Color(0, 0, 255));
        jPanelSemQualPart.setMinimumSize(new java.awt.Dimension(0, 0));

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));

        jButtonNewFormalConcept.setText("+");
        jButtonNewFormalConcept.setToolTipText("Create a new formal concept");
        jButtonNewFormalConcept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonNewFormalConceptActionPerformed(evt);
            }
        });

        jScrollPane4.setBackground(new java.awt.Color(158, 162, 223));
        jScrollPane4.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jScrollPane4.setAutoscrolls(true);
        jScrollPane4.setName("Formal Concepts"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.Alignment.TRAILING)
            .addComponent(jButtonNewFormalConcept, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButtonNewFormalConcept)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4))
        );

        saveSemQuaBtn.setText("Save it!");
        saveSemQuaBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveSemQuaBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanelSemQualPartLayout = new javax.swing.GroupLayout(jPanelSemQualPart);
        jPanelSemQualPart.setLayout(jPanelSemQualPartLayout);
        jPanelSemQualPartLayout.setHorizontalGroup(
            jPanelSemQualPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSemQualPartLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelSemQualPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelSemQualPartLayout.createSequentialGroup()
                        .addGap(0, 83, Short.MAX_VALUE)
                        .addComponent(saveSemQuaBtn)))
                .addContainerGap())
        );
        jPanelSemQualPartLayout.setVerticalGroup(
            jPanelSemQualPartLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelSemQualPartLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(saveSemQuaBtn)
                .addContainerGap())
        );

        javax.swing.GroupLayout jPanelContainerLayout = new javax.swing.GroupLayout(jPanelContainer);
        jPanelContainer.setLayout(jPanelContainerLayout);
        jPanelContainerLayout.setHorizontalGroup(
            jPanelContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelContainerLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelFormPart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelSemQualPart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelOntologyPart, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanelContainerLayout.setVerticalGroup(
            jPanelContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanelContainerLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelContainerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jPanelFormPart, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelOntologyPart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 393, Short.MAX_VALUE)
                    .addComponent(jPanelSemQualPart, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jMenu3.setText("Application");

        jMenu4.setText("Language");

        jMenuItem1.setText("English");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem1);

        jMenuItem2.setText("Française");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu4.add(jMenuItem2);

        jMenuItem3.setText("Español");
        jMenu4.add(jMenuItem3);
        jMenu4.add(jSeparator2);

        jMenu3.add(jMenu4);

        jMenuAbout.setText("About");
        jMenuAbout.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuAboutActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuAbout);

        jMenuQuit.setText("Quit");
        jMenuQuit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuQuitActionPerformed(evt);
            }
        });
        jMenu3.add(jMenuQuit);
        jMenu3.add(jSeparator1);

        jMenuBar1.add(jMenu3);

        jMenu1.setText("Semantic");

        jMenuNewSemanticQual.setText("New Semantic Qualification");
        jMenuNewSemanticQual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewSemanticQualActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuNewSemanticQual);

        jMenuOpenOntology.setText("Open Ontology...");
        jMenuOpenOntology.setEnabled(false);
        jMenuOpenOntology.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuOpenOntologyActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuOpenOntology);

        jMenuNewFormalConcept.setText("New Formal Concept");
        jMenuNewFormalConcept.setEnabled(false);
        jMenuNewFormalConcept.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuNewFormalConceptActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuNewFormalConcept);

        jMenuSaveSemQual.setText("Save Semantic Qualification");
        jMenuSaveSemQual.setEnabled(false);
        jMenuSaveSemQual.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuSaveSemQualActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuSaveSemQual);

        jMenuBar1.add(jMenu1);

        jMenu5.setText("Form");

        jMenuOpenForm.setText("Open Form...");
        jMenuOpenForm.setEnabled(false);
        jMenuOpenForm.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuOpenFormActionPerformed(evt);
            }
        });
        jMenu5.add(jMenuOpenForm);

        jMenuBar1.add(jMenu5);

        jMenu2.setText("Help");

        jMenuOnlineHelp.setText("Online Help");
        jMenuOnlineHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuOnlineHelpActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuOnlineHelp);

        jMenuBar1.add(jMenu2);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelContainer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void openHtmlBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openHtmlBtnActionPerformed
        // show the file chooser window and then get the owl file
        openFile = new JFileChooser();
        openFile.setDialogTitle("Open an Html form file (*.html | *.htm | *.xhtml)");

        openFile.setFileFilter(new FilterExtension("html", "The html file"));
        openFile.addChoosableFileFilter(new FilterExtension("xhtml", "The xhtml file"));
        openFile.addChoosableFileFilter(new FilterExtension("htm", "The html file"));
        int returnVal = openFile.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = openFile.getSelectedFile();
            //Getting the file name and setting the tree
            htmlFormUrl = file.getPath();
            setHtmlFormTree();
        } else {
            // no file was chosen
            System.out.println("No html file was chosen!");
        }
    }//GEN-LAST:event_openHtmlBtnActionPerformed

    private void jMenuNewSemanticQualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewSemanticQualActionPerformed
        jPanelContainer.setVisible(true);
        jMenuNewFormalConcept.setEnabled(true);
        jMenuNewSemanticQual.setEnabled(false);
        jMenuSaveSemQual.setEnabled(true);
        jMenuOpenForm.setEnabled(true);
        jMenuOpenOntology.setEnabled(true);
        
        SemanticQualificationController.createSemanticQualificationControl();
        JOptionPane.showMessageDialog(this,
            "Semantic Qualification was created. Now please open the form you wish to qualify");
    }//GEN-LAST:event_jMenuNewSemanticQualActionPerformed

    private void jButtonNewFormalConceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonNewFormalConceptActionPerformed
        // create new semantic qualification
        
	// open the window NewFC
        this.sqc.createSemanticQualificationControl();
	NewFC1 jf1=new NewFC1(this);
	this.setEnabled(false);
	jf1.setVisible(true); 
    }//GEN-LAST:event_jButtonNewFormalConceptActionPerformed
        
    private void jMenuOpenFormActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenFormActionPerformed
        openHtmlBtnActionPerformed(evt);
    }//GEN-LAST:event_jMenuOpenFormActionPerformed

    private void jMenuOpenOntologyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOpenOntologyActionPerformed
        openOwlBtnActionPerformed(evt);
    }//GEN-LAST:event_jMenuOpenOntologyActionPerformed

    private void jMenuNewFormalConceptActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuNewFormalConceptActionPerformed
        jButtonNewFormalConceptActionPerformed(evt);
    }//GEN-LAST:event_jMenuNewFormalConceptActionPerformed

    private void jMenuSaveSemQualActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuSaveSemQualActionPerformed
        saveSemQuaBtnActionPerformed(evt);
    }//GEN-LAST:event_jMenuSaveSemQualActionPerformed

    private void jMenuQuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuQuitActionPerformed
        try {
            int reponse = JOptionPane.showConfirmDialog(this, "Are you sure you want to quit the application ?", "quit application", JOptionPane.OK_CANCEL_OPTION);
            if (reponse == JOptionPane.OK_OPTION) {
                System.exit(EXIT_ON_CLOSE);
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, e.getMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_jMenuQuitActionPerformed

    private void jMenuAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuAboutActionPerformed
        new About().setVisible(true);
        // TODO : improve the about form 
        // and handle when we close the about form, the principal form should stay
    }//GEN-LAST:event_jMenuAboutActionPerformed

    private void jMenuOnlineHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuOnlineHelpActionPerformed
        JOptionPane.showMessageDialog(this,"We are sorry, this functionnality is not available for the moment","Online Help",JOptionPane.INFORMATION_MESSAGE);
        
    }//GEN-LAST:event_jMenuOnlineHelpActionPerformed

    private void saveSemQuaBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveSemQuaBtnActionPerformed
        // TODO add your handling code here:
        System.out.println("save button");
        if (sqc != null){
            sqc.writeOutputFile(sqc.generateFileContent());
        } else {
            System.out.println("Semantic Qualification Controller is null !!");
        }
    }//GEN-LAST:event_saveSemQuaBtnActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jTextFieldSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldSearchActionPerformed
        // TODO add your handling code here:
        setOntologyTree(jTextFieldSearch.getText());
    }//GEN-LAST:event_jTextFieldSearchActionPerformed

    private void jRadioButtonAttOffActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAttOffActionPerformed
        // TODO add your handling code here:
        displayAttributes = false;
        setOntologyTree(jTextFieldSearch.getText());
    }//GEN-LAST:event_jRadioButtonAttOffActionPerformed

    private void openOwlBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openOwlBtnActionPerformed
        // show the file chooser window and then get the owl file
        openFile = new JFileChooser();
        openFile.setDialogTitle("Open an ontology file (*.owl)");
        // openFile.addChoosableFileFilter(new FilterExtension("owl", "The ontology file"));
        openFile.setFileFilter(new FilterExtension("owl", "The ontology file"));
        int returnVal = openFile.showOpenDialog(this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = openFile.getSelectedFile();
            //Getting the file name and setting the tree
            ontologyUrl = file.getPath();
            setOntologyTree();
        } else {
            // no file was chosen
            System.out.println("No ontology file was chosen!");
        }
    }//GEN-LAST:event_openOwlBtnActionPerformed

    private void jRadioButtonAttOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonAttOnActionPerformed
        // TODO add your handling code here:
        displayAttributes = true;
        setOntologyTree(jTextFieldSearch.getText());
    }//GEN-LAST:event_jRadioButtonAttOnActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PrincipalWindowGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PrincipalWindowGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PrincipalWindowGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PrincipalWindowGUI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new PrincipalWindowGUI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroupDisplayAttributes;
    private javax.swing.JTree formTree;
    private javax.swing.JButton jButtonNewFormalConcept;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabelOntologyName;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenu jMenu5;
    private javax.swing.JMenuItem jMenuAbout;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuNewFormalConcept;
    private javax.swing.JMenuItem jMenuNewSemanticQual;
    private javax.swing.JMenuItem jMenuOnlineHelp;
    private javax.swing.JMenuItem jMenuOpenForm;
    private javax.swing.JMenuItem jMenuOpenOntology;
    private javax.swing.JMenuItem jMenuQuit;
    private javax.swing.JMenuItem jMenuSaveSemQual;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanelContainer;
    private javax.swing.JPanel jPanelFormPart;
    private javax.swing.JPanel jPanelOntologyDisplay;
    private javax.swing.JPanel jPanelOntologyHeader;
    private javax.swing.JPanel jPanelOntologyPart;
    private javax.swing.JPanel jPanelSemQualPart;
    private javax.swing.JRadioButton jRadioButtonAttOff;
    private javax.swing.JRadioButton jRadioButtonAttOn;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JTextField jTextFieldSearch;
    private javax.swing.JTree ontologyTree;
    private javax.swing.JButton openHtmlBtn;
    private javax.swing.JButton openOwlBtn;
    private javax.swing.JButton saveSemQuaBtn;
    // End of variables declaration//GEN-END:variables
}
